<?php

namespace app\services;

use app\model\Airlines;
use app\model\City;
use app\model\CodPerformance;
use app\model\CodStatement;

class MergeService
{

    public function __construct()
    {
    }

    public function hotelKing2order($excelResult)
    {
        $cityDao = new City();
        $cityList = $cityDao->select();
        $cityArr = [];
        foreach ($cityList as $city){
            $cityArr[$city['city']] = $city['city_name'] == $city['province'] ? $city['city_name'] : $city['city_name'].','.$city['province'];
        }


        $airlinesDao = new Airlines();

        $airlinesList = $airlinesDao->select();
        $airlinesArr = [];
        foreach ($airlinesList as $airlines){
            $airlinesArr[$airlines['ticket_header']] = $airlines['airlines_name'];
        }
        
        $codPerformanceService = new CodPerformanceService();
        $codStatementService = new CodStatementService();
        $saveCodPerformanceList = [];
        $saveCodStatementList = [
            'error'=>[],
            'reform'=>[],
            'good'=>[],
            'connecting'=>[],
        ];
        foreach ($excelResult as $orderArr) {
            //只要客户名称 包含COD的
            if (!preg_match('/COD/', $orderArr[6])) continue;

            $CodPerformance = $codPerformanceService->setBatchSaveCodPerformanceList($orderArr);
            $saveCodPerformanceList[] = $CodPerformance;


            $saveCodStatement = $codStatementService->setBatchSaveCodStatementList($orderArr, $cityArr, $airlinesArr);

            empty($saveCodStatement['error']) || $saveCodStatementList['error'] = array_merge($saveCodStatementList['error'], $saveCodStatement['error']);
            empty($saveCodStatement['reform']) || $saveCodStatementList['reform'] = array_merge($saveCodStatementList['reform'], $saveCodStatement['reform']);
            empty($saveCodStatement['good']) || $saveCodStatementList['good'] = array_merge($saveCodStatementList['good'], $saveCodStatement['good']);
            empty($saveCodStatement['connecting']) || $saveCodStatementList['connecting'] = array_merge($saveCodStatementList['connecting'], $saveCodStatement['connecting']);

        }
        $codPerformanceService->addBatch($saveCodPerformanceList);
        return$saveCodStatementList;
    }









}